package com.ext.aic.apis.chat;

import android.content.Context;

import androidx.lifecycle.LifecycleOwner;

import com.ext.aic.apis.ApiDefine;
import com.ext.aic.apis.ApiPaths;
import com.ext.aic.apis.RequestResponse;
import com.ext.aic.beans.params.AgentReplyParams;
import com.ext.aic.beans.response.AgentReplyResponse;
import com.ext.aic.beans.response.Response;
import com.ext.aic.utils.ToastyUtils;
import com.eyinfo.android_pure_utils.utils.JsonUtils;
import com.hjq.http.EasyHttp;
import com.hjq.http.body.JsonRequestBody;

public class AgentReplyRequest {
    protected void onAgentReplySuccess(AgentReplyParams params, AgentReplyResponse response) {

    }

    protected void onAgentReplyFail() {

    }

    public void request(Context context, LifecycleOwner lifecycleOwner, AgentReplyParams params) {
        EasyHttp.post(lifecycleOwner)
                .api(new ApiDefine(ApiPaths.agentReply))
                .body(new JsonRequestBody(JsonUtils.toJson(params)))
                .request(new RequestResponse<Response<AgentReplyResponse>>(context, false) {
                    @Override
                    protected void onSuccess(Response<AgentReplyResponse> response) {
                        if (response.getCode() == 200) {
                            onAgentReplySuccess(params, response.getData());
                        } else {
                            ToastyUtils.getInstance().show(response.getMessage());
                        }
                    }

                    @Override
                    public void onHttpFail(Throwable throwable) {
                        super.onHttpFail(throwable);
                        onAgentReplyFail();
                    }
                });
    }
}
